package com.broada.apm.indicator.api.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.broada.apm.dao.ResourceDao;
import com.broada.apm.indicator.api.ResourceService;
import com.broada.apm.model.Resource;

public class ResourceServiceImpl implements ResourceService {

	@Autowired
	private ResourceDao resourceDao;
	
	@Override
	public void addResource(Resource resource) {
		resourceDao.addResource(resource);
	}

	@Override
	public void updateResource(Resource resource) {
//		resourceDao.updateResource(resource);
	}

	@Override
	public void deleteResource(Resource resource) {
		resourceDao.deleteResource(resource);
	}

	@Override
	public Resource getResourceById(String resId) {
		return resourceDao.getResourceById(resId);
	}

	@Override
	public List<Resource> getKeyResourcesByAppId(String appId) {
		Resource res = new Resource();
		res.setApplicationId(appId);
		return resourceDao.getKeyResourcesByAppId(res);
	}

	@Override
	public List<Resource> getAllResources() {
		return resourceDao.getAllResources();
	}

	@Override
	public List<Resource> getResourcesByCondition(Resource resource) {
		return resourceDao.getResourcesByCondition(resource);
	}

	@Override
	public Resource getResourceByName(String txName) {
		List<Resource> list = resourceDao.getResourceByName(txName);
		if (!list.isEmpty()) {
			return list.get(0);
		}
		return null;
	}

	@Override
	public List<Resource> getResourceByIds(List<String> resourceIds) {
		return resourceDao.getResourceByIds(resourceIds);
	}

	@Override
	public void addKeyResource(Resource resource) {
		resourceDao.addKeyResource(resource);
	}

	@Override
	public void updateKeyResource(Resource resource) {
		resourceDao.updateKeyResource(resource);
	}

	@Override
	public Resource getKeyResourceById(String id) {
		return resourceDao.getKeyResourceById(id);
	}

	@Override
	public List<Resource> getKeyResourcesByCondition(Resource resource) {
		return resourceDao.getKeyResourcesByCondition(resource);
	}

	@Override
	public List<Resource> getKeyResourceByIds(List<String> resIds) {
		return resourceDao.getKeyResourceByIds(resIds);
	}

	@Override
	public Resource getKeyResourceByUri(String txName, String appId, String serviceId) {
		List<Resource> list = resourceDao.getKeyResourceByUri(txName, appId, serviceId);
		if (!list.isEmpty()) {
			return list.get(0);
		}
		return null;
	}

	@Override
	public List<String> getKeyResourceIdsByCondition(Resource resource) {
		return resourceDao.getKeyResourceIdsByCondition(resource);
	}

	@Override
	public List<Resource> getResourcesByKeyWord(Resource resource) {
		return resourceDao.getResourcesByKeyWord(resource);
	}

}
